package main

import (
	"RocFamilySystem/config"
	_ "RocFamilySystem/docs"
	"RocFamilySystem/models"
	"RocFamilySystem/pkg/database"
	"RocFamilySystem/pkg/nosql"
	"RocFamilySystem/router"
	"RocFamilySystem/tools/cache"
	"RocFamilySystem/tools/container"
	"fmt"
	"github.com/gin-gonic/gin"
	swaggerFiles "github.com/swaggo/files"
	ginSwagger "github.com/swaggo/gin-swagger"
	"log"
)

func main() {

	log.SetFlags(log.Llongfile | log.Ltime)

	//初始化配置文件
	config.InitConfiguration()
	//初始化数据库
	database.InitMysqlDatabase()
	//初始化模型
	models.InitRegisterModels()
	//初始化Redis
	nosql.InitRedis()
	//初始化gin
	engine := gin.Default()
	container.PushContainer(engine)
	//初始化路由
	router.InitRouter()
	//加载全部缓存
	cache.LoadAllSysCache()

	//添加swagger访问路由
	engine.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
	log.Printf("swagger访问地址：%s:%d%s", "http://localhost", config.GlobalConfig.Server.Port, "/swagger/index.html")

	if err := engine.Run(fmt.Sprintf("%s:%d", config.GlobalConfig.Server.Host, config.GlobalConfig.Server.Port)); err != nil {
		log.Println("启动失败：", err.Error())
	}
}
